# Maintainer: Lucio Perusini <lucioperusini@gmail.com>

_realname=i2pd
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=2.39.0
pkgrel=1
pkgdesc='A full-featured C++ implementation of the I2P router (mingw-w64)'
url='https://i2pd.website/'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-miniupnpc")
options=('strip')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/PurpleI2P/i2pd/archive/${pkgver}.tar.gz"
        "0001-i2pd-endian.patch"
        "0001-i2pd-dont-use-pthread_setname.patch"
        "0001-i2pd-makefile.patch")
sha256sums=('3ffeb614cec826e13b50e8306177018ecb8d873668dfe66aadc733ca9fcaa568'
            '643e996fdb0ee422fbba5608210dd3803a02a8e73adcb4bae540ab0591967df6'
            '94581b519676ecb4e7fd9d9ddc7c113ea3d2d8d4ff50c13f563e325711c17bf5'
            '6df9fe849539abdda74a281e5df1ba2c82d56690de9edc640c5e5212f865a626')
noextract=("${_realname}-${pkgver}.tar.gz") # symlinks
prepare() {
  cd "${srcdir}"
  bsdtar -xf "${_realname}-${pkgver}.tar.gz" || true
  cd "${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}"/0001-i2pd-endian.patch
  patch -Np1 -i "${srcdir}"/0001-i2pd-dont-use-pthread_setname.patch
  patch -Np1 -i "${srcdir}"/0001-i2pd-makefile.patch
}

build() {
  cp -rf "${_realname}-${pkgver}" "build-${MSYSTEM}"
  cd "${srcdir}"/build-${MSYSTEM}

  make USE_AESNI=no USE_UPNP=yes USE_MESHNET=yes
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}

  #bin
  install -d "${pkgdir}${MINGW_PREFIX}/bin/"
  cp i2pd.exe "${pkgdir}${MINGW_PREFIX}/bin/"

  #config
  install -d "${pkgdir}${MINGW_PREFIX}/etc/i2pd"
  cp contrib/{i2pd,tunnels}.conf "${pkgdir}${MINGW_PREFIX}/etc/i2pd"
  install -d "${pkgdir}${MINGW_PREFIX}/etc/i2pd/tunnels.d"

  # certificates
  install -d "${pkgdir}${MINGW_PREFIX}/share/i2pd"
  cp -r contrib/certificates "${pkgdir}${MINGW_PREFIX}/share/i2pd"

  # license
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
